<?php
class admin_login extends MX_Controller{
	public function index(){
		global $CFG;

		$this->load->library('session');
		$url=$CFG->config['base_url'].'admin';
		$this->load->helper('url');
		
		if(isset($_POST)){
			if(isset($_POST['log']) and isset($_POST['pwd'])){
				$checkIdAdmin=$this->model()->login($_POST['log'],$_POST['pwd']);
				if($checkIdAdmin){					
					if($this->session->userdata('admin')) $this->session->unset_userdata('admin'); 					
					if($url=$this->session->userdata('back_url')){
						$this->session->unset_userdata('back_url');
					}else $url=$CFG->config['base_url'].'category/admin';
						$this->session->set_userdata('admin',$checkIdAdmin);
					if(isset($_POST['rememberme'])){
						setcookie("admin", $checkIdAdmin, time()+3600);
					}
				}
				
			}
		}
		redirect($url);
	}
}